﻿<%@ Page Title="" Language="C#" MasterPageFile="~/UI/Main.Master" AutoEventWireup="true" CodeBehind="dsnhanvien.aspx.cs" Inherits="QLBH.UI.dsnhanvien" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <style type="text/css">
        .popover {
            width: 276px;
        }

        .popover-title {
            padding: 0px;
        }


        .popover-content {
            max-height: 276px;
            overflow: auto;
        }

        table th {
            font-size: 16px;
        }

        #table_quyen th {
            font-size: inherit;
        }

        table tr td {
            text-align: left;
        }
    </style>


    <div class="row">
        <div class="col-md-4">
        </div>
        <div class="col-md-4 text-right" style="padding-bottom: 5px;">
            <span id="btn_refresh" class="btn btn-success"><span class="glyphicon glyphicon-refresh"></span></span>
            <span id="btn_add" data-toggle="popover" class="btn btn-primary">&nbsp<span class="glyphicon glyphicon-plus"></span></span>
            <span id="btn_edit" data-toggle="popover" class="btn btn-primary"><span class="glyphicon glyphicon-pencil"></span></span>
            <span id="btn_delete" data-toggle="popover" class="btn btn-danger"><span class="glyphicon glyphicon-trash"></span></span>

        </div>
        <div class="col-md-4 text-right">
            <div class="form-group">
                <input type="search" class="form-control" id="txt_search" placeholder="Nhập vào tên nhân viên" />
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-md-12 text-center" id="lazyScroll" style="overflow: auto; max-height: 310px;">

            <table id="table_nhan_vien" class="table table-bordered " style="min-width: 900px;">
                <thead>
                    <tr>
                        <th class="text-center" style="width: 30px;">
                            <input id="chk_check_all" type="checkbox" value="-1" />
                        </th>
                        <th class="text-center" style="width: 50px;">STT</th>
                        <th style="width: 100px;">Mã NV</th>
                        <th>Họ </th>
                        <th>Tên </th>
                        <th>Ngày sinh</th>
                        <th>Điện thoại</th>
                        <th>Email</th>
                        <th>Phòng ban</th>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>

    <div id="popoverExampleTwoHiddenContent" style="display: none">

        <form role="form">
            <label id="lbl_lan_sua_cuoi" class="hidden"></label>

            <div class="form-group">
                <label for="cbo_gioi_tinh">Phòng ban</label>
                <select class="form-control" id="cbo_phong_ban">
                </select>
            </div>

            <div class="form-group">
                <label for="txt_ma_nv">Mã nhân viên</label>
                <input type="text" class="form-control" name="txt_ma_nv" id="txt_ma_nv" placeholder="Mã nhân viên" />
            </div>

            <div class="form-group">
                <label for="txt_ho">Họ</label>
                <input type="text" class="form-control" name="txt_ho" id="txt_ho" placeholder="Họ" />
            </div>

            <div class="form-group">
                <label for="txt_ten">Tên</label>
                <input type="text" class="form-control" name="txt_ten" id="txt_ten" placeholder="Tên" />
            </div>

            <div class="form-group">
                <label for="txt_ngay_sinh">Ngày sinh</label>
                <input class="form-control datepicker" name="txt_ngay_sinh" id="txt_ngay_sinh" placeholder="Ngày sinh" />
            </div>

            <div class="form-group">
                <label for="txt_dien_thoai">Điện thoại</label>
                <input type="tel" class="form-control" name="txt_dien_thoai" id="txt_dien_thoai" placeholder="Điện thoại" />
            </div>

            <div class="form-group">
                <label for="txt_email">Email</label>
                <input type="email" class="form-control" name="txt_email" id="txt_email" placeholder="Email" />
            </div>

            <div class="form-group">
                <label for="cbo_gioi_tinh">Giới tính</label>
                <select class="form-control" id="cbo_gioi_tinh">
                    <option value="0">Nam</option>
                    <option value="1">Nữ</option>
                    <option value="2">Khác</option>
                </select>
            </div>
             <div class="form-group">
                <label for="txt_cmnd">Số CMND</label>
                <input type="text" class="form-control" name="txt_cmnd" id="txt_cmnd" placeholder="Số CMND" />
            </div>
            <div class="form-group">
                <label for="txt_ngay_thue">Ngày thuê</label>
                <input type="text" class="form-control datepicker" name="txt_ngay_thue" id="txt_ngay_thue" placeholder="Ngày thuê" />
            </div>


            <div class="form-group">
                <label for="txt_dia_chi">Địa chỉ</label>
                <textarea rows="2" class="form-control" name="txt_dia_chi" id="txt_dia_chi" placeholder="Địa chỉ"></textarea>
            </div>

            <div class="form-group">
                <label for="txt_ms_thue">Mã số thuế</label>
                <input type="text" class="form-control" name="txt_ms_thue" id="txt_ms_thue" placeholder="Mã số thuế" />
            </div>

            <div class="form-group">
                <label for="txt_ghi_chu">Ghi Chú</label>
                <textarea rows="2" class="form-control" name="txt_ghi_chu" id="txt_ghi_chu" placeholder="Ghi chú"></textarea>
            </div>


            <button id="btn_save" type="submit" class="btn btn-primary pull-right">&nbsp&nbsp Lưu &nbsp&nbsp  </button>
        </form>

    </div>


    <!-- Popover 2 hidden title -->
    <div id="popoverExampleTwoHiddenTitle" style="display: none;">
        <h4 class="text-center">Cập nhật nhân viên</h4>
    </div>


    <script src="slidebars/scripts/bootstrap/js/jquery.min.js"></script>
    <script src="slidebars/scripts/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {

            $("#lazyScroll").scroll(function () {
                if ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) {
                    //BlockUI();
                    //var tables = document.getElementById("table_nhan_vien");
                    //var search_term = $("#txt_search").val();
                    //TimNhanVien(search_term, tables.rows.length - 1);
                }
            });


            function Kiemtrahople() {
                if ($('#txt_ten').val().length <= 0) {
                    $('#txt_ten').focus();
                    $('#txt_ten').tooltip({ placement: 'top', title: 'Bạn cần nhập Tên' });
                    return false;
                }

                if ($('#txt_ho').val().length <= 0) {
                    $('#txt_ho').focus();
                    $('#txt_ho').tooltip({ placement: 'top', title: 'Bạn cần nhập Họ' });
                    return false;
                }

                if ($('#txt_ngay_sinh').val().length <= 0) {
                    $('#txt_ngay_sinh').focus();
                    $('#txt_ngay_sinh').tooltip({ placement: 'top', title: 'Bạn cần nhập ngày sinh' });
                    return false;
                }

                if ($('#txt_ngay_thue').val().length <= 0) {
                    $('#txt_ngay_thue').focus();
                    $('#txt_ngay_thue').tooltip({ placement: 'top', title: 'Bạn cần nhập ngày thuê' });
                    return false;
                }

                if ($('#txt_dia_chi').val().length <= 0) {
                    $('#txt_dia_chi').focus();
                    $('#txt_dia_chi').tooltip({ placement: 'top', title: 'Bạn cần nhập địa chỉ' });
                    return false;
                }

                if ($('#txt_dien_thoai').val().length <= 0) {
                    $('#txt_dien_thoai').focus();
                    $('#txt_dien_thoai').tooltip({ placement: 'top', title: 'Bạn cần nhập điện thoại' });
                    return false;
                }
                if ($('#txt_email').val().length <= 0) {
                    $('#txt_email').focus();
                    $('#txt_email').tooltip({ placement: 'top', title: 'Bạn cần nhập Email' });
                    return false;
                }

                if ($('#txt_cmnd').val().length <= 0) {
                    $('#txt_cmnd').focus();
                    $('#txt_cmnd').tooltip({ placement: 'top', title: 'Bạn cần nhập Số CMND' });
                    return false;
                }

                return true;
            }

            function XoaText() {
                $('#txt_ma_nv').val('');
                $('#txt_ten').val('');
                $('#txt_dia_chi').val('');
                $('#txt_dien_thoai').val('');
                $('#txt_email').val('');
                $('#txt_ghi_chu').val('');
                $('#txt_ho').val('');
                $('#txt_ten').val('');
                $('#txt_cmnd').val('');
                $('#txt_ms_thue').val('');
            }

            function BlockUI() {
                $.blockUI({
                    message: "<img src='images/ajax-loader.gif'/>", css: { left: '50%', cursor: 'wait', backgroundColor: 'none', border: 'none', width: '50px' },
                    overlayCSS: { backgroundColor: 'none', opacity: 0.0, cursor: 'wait' }
                });
            }

            function BlockUIPopover() {
                $('.popover').block({
                    message: "<img src='images/ajax-loader.gif'/>", css: { left: '50%', cursor: 'wait', backgroundColor: 'none', border: 'none', width: '50px' },
                    overlayCSS: { backgroundColor: 'none', opacity: 0.0, cursor: 'wait' }
                });
            }


            function getFDate(dateObject) {

                var today = new Date(dateObject);
                if (dateObject == '') {
                    today = new Date();
                }
                var dd = today.getDate();
                var mm = today.getMonth() + 1; //January is 0!

                var yyyy = today.getFullYear();
                if (dd < 10) {
                    dd = '0' + dd
                }
                if (mm < 10) {
                    mm = '0' + mm
                }
                var today = dd + '/' + mm + '/' + yyyy;
                return today;
            }


            function TimNhanVien(ten_nhan_vien, tong_so_dong) {

                var DTO = {
                    'ten_nhan_vien': ten_nhan_vien,
                    'tong_so_dong': tong_so_dong
                };
                $.ajax({
                    type: "POST",
                    url: "../BUSINESS/Services.asmx/TimNhanVienTheoTen",
                    data: JSON.stringify(DTO),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {

                        $.each($.parseJSON(data.d), function (idx, obj) {
                            tong_so_dong += 1;
                            $("#table_nhan_vien tbody").append(
                            '<tr>' +
                            ' <td>' +
                            ' <input type="checkbox" value="' + tong_so_dong + '" />' +
                            ' </td>' +
                            ' <td>' + tong_so_dong + '</td>' +
                            ' <td>' + obj.MA_NHAN_VIEN + '</td>' +
                            ' <td>' + obj.HO + '</td>' +
                            ' <td>' + obj.TEN + '</td>' +
                            ' <td>' + getFDate(obj.NGAY_SINH) + '</td>' +
                            ' <td>' + obj.DIEN_THOAI + '</td>' +
                            ' <td>' + obj.EMAIL + '</td>' +
                            ' <td>' + obj.PHONG_BAN.TEN_PHONG_BAN + '</td>' +
                            ' <td class ="hidden">' + obj.PHONG_BAN.MA_PHONG_BAN + '</td>' +
                            ' <td class ="hidden">' + obj.GIOI_TINH + '</td>' +
                            ' <td class ="hidden">' + obj.SO_CMND + '</td>' +
                            ' <td class ="hidden">' + obj.NGAY_THUE + '</td>' +
                            ' <td class ="hidden">' + obj.DIA_CHI + '</td>' +
                            ' <td class ="hidden">' + obj.MA_SO_THUE + '</td>' +
                            ' <td class ="hidden">' + obj.GHI_CHU + '</td>' +
                            ' <td class ="hidden"> ' + obj.NGUOI_SUA + '</td>' +
                            ' <td class ="hidden">' + obj.LAN_SUA_CUOI + '</td>' +
                            ' </tr>');
                        });

                    },
                    error: function (data) {
                        console.log(data.d);
                    }

                });
            }

            onload = function () {
                BlockUI();
                var tables = document.getElementById("table_nhan_vien");
                TimNhanVien('', tables.rows.length - 1);
                TimPhongBan('', 0);
            }

            function ThemMoiNhanVien() {
                if (!Kiemtrahople()) {
                    return false;
                }
                BlockUIPopover();
                var NHANVIEN = {};
                NHANVIEN.MA_NHAN_VIEN = $('#txt_ma_nv').val();
                NHANVIEN.MA_PHONG_BAN = $("#cbo_phong_ban option:selected").val();
                NHANVIEN.HO = $('#txt_ho').val();
                NHANVIEN.TEN = $('#txt_ten').val();

                var dates = $('#txt_ngay_sinh').val().split('/');
                dates.reverse();
                var reversed = dates.join('-');

                NHANVIEN.NGAY_SINH = reversed;

                dates = $('#txt_ngay_thue').val().split('/');
                dates.reverse();
                reversed = dates.join('-');

                NHANVIEN.NGAY_THUE = reversed;
                NHANVIEN.DIA_CHI = $('#txt_dia_chi').val();
                NHANVIEN.DIEN_THOAI = $('#txt_dien_thoai').val();
                NHANVIEN.GIOI_TINH = $("#cbo_gioi_tinh option:selected").val();
                NHANVIEN.MA_SO_THUE = $('#txt_ms_thue').val();
                NHANVIEN.SO_CMND = $('#txt_cmnd').val();
                NHANVIEN.GHI_CHU = $('#txt_ghi_chu').val();
                NHANVIEN.NGUOI_SUA = '';
                NHANVIEN.EMAIL = $('#txt_email').val();

                var DTO = {
                    'NHANVIEN': NHANVIEN
                };

                $.ajax({
                    type: "POST",
                    url: "../BUSINESS/Services.asmx/ThemMoiNhanVien",
                    data: JSON.stringify(DTO),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        $(".popover").unblock();
                        var obj = jQuery.parseJSON(data.d);
                        if (obj.SUCCESS == -1) {
                            MakeToast('danger', 'Lỗi', obj.ERROR);
                        }
                        else {
                            MakeToast('success', 'Thành công', obj.ERROR);
                            XoaText();
                            $("#table_nhan_vien tbody").html('');
                            var tables = document.getElementById("table_nhan_vien");
                            var search_term = $("#txt_search").val();
                            TimNhanVien(search_term, tables.rows.length - 1);
                        }

                    },
                    error: function (data) {
                        $(".popover").unblock();
                    }

                });
            }

            function CapNhatNhanVien() {
                if (!Kiemtrahople()) {
                    return false;
                }
                BlockUIPopover();
                var NHANVIEN = {};
                NHANVIEN.MA_NHAN_VIEN = $('#txt_ma_nv').val();
                NHANVIEN.MA_PHONG_BAN = $("#cbo_phong_ban option:selected").val();
                NHANVIEN.HO = $('#txt_ho').val();
                NHANVIEN.TEN = $('#txt_ten').val();

                var dates = $('#txt_ngay_sinh').val().split('/');
                dates.reverse();
                var reversed = dates.join('-');

                NHANVIEN.NGAY_SINH = reversed;

                dates = $('#txt_ngay_thue').val().split('/');
                dates.reverse();
                reversed = dates.join('-');

                NHANVIEN.NGAY_THUE = reversed;
                NHANVIEN.DIA_CHI = $('#txt_dia_chi').val();
                NHANVIEN.DIEN_THOAI = $('#txt_dien_thoai').val();
                NHANVIEN.GIOI_TINH = $("#cbo_gioi_tinh option:selected").val();
                NHANVIEN.MA_SO_THUE = $('#txt_ms_thue').val();
                NHANVIEN.SO_CMND = $('#txt_cmnd').val();
                NHANVIEN.GHI_CHU = $('#txt_ghi_chu').val();
                NHANVIEN.NGUOI_SUA = '';
                NHANVIEN.EMAIL = $('#txt_email').val();
                NHANVIEN.LAN_SUA_CUOI = $('#lbl_lan_sua_cuoi').html();

                var DTO = {
                    'NHANVIEN': NHANVIEN
                };

                $.ajax({
                    type: "POST",
                    url: "../BUSINESS/Services.asmx/CapNhatNhanVien",
                    data: JSON.stringify(DTO),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        $(".popover").unblock();
                        var obj = jQuery.parseJSON(data.d);
                        if (obj.SUCCESS == -1) {
                            MakeToast('danger', 'Lỗi', obj.ERROR);
                        }
                        else {
                            MakeToast('success', 'Thành công', obj.ERROR);
                            $("#table_nhan_vien tbody").html('');
                            var tables = document.getElementById("table_nhan_vien");
                            var search_term = $("#txt_search").val();
                            TimNhanVien(search_term, tables.rows.length - 1);
                        }

                    },
                    error: function (data) {
                        $(".popover").unblock();
                    }

                });
            }

            function XoaNhanVien() {

                BlockUIPopover();
                var ma_nhan_vien = [];

                var tables = document.getElementById("table_nhan_vien");
                var k = -1;
                for (var i = 1; i < tables.rows.length; i++) {
                    var row = tables.rows[i]
                    if (row.className == 'info') {
                        k++;
                        ma_nhan_vien[k] = row.cells[2].innerHTML;
                    }
                }

                var DTO = {
                    'ma_nhan_vien': ma_nhan_vien
                };
                $.ajax({
                    type: "POST",
                    url: "../BUSINESS/Services.asmx/XoaNhanVien",
                    data: JSON.stringify(DTO),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (data) {
                        $(".popover").unblock();
                        var obj = jQuery.parseJSON(data.d);
                        if (obj.SUCCESS == -1) {
                            MakeToast('danger', 'Lỗi', obj.ERROR);
                        }
                        else {
                            MakeToast('success', 'Thành công', obj.ERROR);
                            $("#btn_delete").popover('hide');
                            $("#table_nhan_vien tbody").html('');
                            var tables = document.getElementById("table_nhan_vien");
                            var search_term = $("#txt_search").val();
                            TimNhanVien(search_term, tables.rows.length - 1);
                        }
                    },
                    error: function (data) {
                        $(".popover").unblock();
                    }

                });
            }

            $('body').on('click', 'span#btn_ok', function (event) {
                event.preventDefault();
                XoaNhanVien();
            });


            $('body').on('click', 'button#btn_save', function (event) {
                event.preventDefault();
                if ($('#txt_ma_nv').is(':disabled')) {
                    CapNhatNhanVien();
                }
                else
                    ThemMoiNhanVien();
            });


            $("#btn_add").click(function (event) {
                event.preventDefault();

            });

            function CheckTableNguoidung() {
                var tables = document.getElementById("table_nhan_vien");
                var k = -1;
                for (var i = 0; i < tables.rows.length; i++) {
                    var row = tables.rows[i]
                    if (row.className == 'info') {
                        k = i;
                        break;
                    }
                }
                return k;
            }

            $("#btn_edit").click(function (event) {
                event.preventDefault();
                var k = CheckTableNguoidung();
                if (k != -1) {
                    $(this).popover('show');
                }
            });


            $("#btn_delete").click(function (event) {
                event.preventDefault();
                var tables = document.getElementById("table_nhan_vien");
                var k = CheckTableNguoidung();
                if (k != -1) {
                    $(this).popover('show');
                }
            });

            $("#btn_refresh").click(function (event) {
                event.preventDefault();
                BlockUI();
                $("#table_nhan_vien tbody").html('');
                var tables = document.getElementById("table_nhan_vien");
                var search_term = $("#txt_search").val();
                TimNhanVien('', tables.rows.length - 1);
            });


            var table = document.getElementById("table_nhan_vien");

            $("table").on("click", ":checkbox", function () {
                if ($(this).val() == -1) {
                    if ($(this).is(':checked')) {
                        $("table tr").addClass("info");
                        $("table tr:first").removeClass("info");
                    }
                    else
                        $("table tr").removeClass("info");
                    return;
                }

                if ($(this).is(':checked')) {
                    $(this).parents("tr:first").addClass("info");
                }
                else {
                    $(this).parents("tr:first").removeClass("info");
                }
            });

            $("#chk_check_all").change(function () {

                if (this.checked) {
                    var table = document.getElementById("table_nhan_vien");
                    $('td input:checkbox', table).prop('checked', this.checked);
                }
                else {
                    var table = document.getElementById("table_nhan_vien");
                    $('td input:checkbox', table).prop('checked', '');
                }
            });

            $("#txt_search").keyup(function (e) {
                if (e.keyCode == 13) {
                    e.preventDefault();
                    e.stopPropagation();
                    var search_term = $("#txt_search").val();
                    if (search_term != '') {
                        BlockUI();
                        $("#table_nhan_vien tbody").html('');
                        var tables = document.getElementById("table_nhan_vien");
                        var search_term = $("#txt_search").val();
                        TimNhanVien(search_term, tables.rows.length - 1);
                    }
                }

            });

            $("#btn_add").popover({
                html: true,
                content: function () {
                    return $('#popoverExampleTwoHiddenContent').html();
                },
                title: function () {
                    return $('#popoverExampleTwoHiddenTitle').html();
                },
                placement: 'bottom'

            });

            $("#btn_edit").popover({
                html: true,
                content: function () {
                    return $('#popoverExampleTwoHiddenContent').html();
                },
                title: function () {
                    return $('#popoverExampleTwoHiddenTitle').html();
                },
                placement: 'bottom',
                trigger: 'Click'

            });

            $("#btn_delete").popover({
                html: true,
                content: function () {

                    return $('#popoverConfirm').html();
                },
                title: function () {
                    return '<h4 class="text-center">Xác nhận xóa</h4>';
                },
                placement: 'bottom',
                trigger: 'Click'

            });


            function getFDate(dateObject) {

                var today = new Date(dateObject);
                if (dateObject == '') {
                    today = new Date();
                }
                var dd = today.getDate();
                var mm = today.getMonth() + 1; //January is 0!

                var yyyy = today.getFullYear();
                if (dd < 10) {
                    dd = '0' + dd
                }
                if (mm < 10) {
                    mm = '0' + mm
                }
                var today = dd + '/' + mm + '/' + yyyy;
                return today;
            }

            $('#btn_add').on('shown.bs.popover', function () {

                $('#txt_ngay_sinh').val(getFDate(''));
                $('#txt_ngay_thue').val(getFDate(''));
                $(".popover-content .datepicker").datepicker();

                var h = $(window).height() - 239;
                $(".popover-content").css({ 'max-height': h });

                //BlockUIPopover();
                //TimPhongBan('', 0);
                //$(".popover").unblock();
            });

            $('#btn_edit').on('shown.bs.popover', function () {

                $(".popover-content .datepicker").datepicker();

                //BlockUIPopover();
                //TimPhongBan('', 0);
                //$(".popover").unblock();

                var tables = document.getElementById("table_nhan_vien");
                var k = -1;
                for (var i = 0; i < tables.rows.length; i++) {
                    var row = tables.rows[i]
                    if (row.className == 'info') {
                        $('#txt_ma_nv').attr("disabled", "disabled")
                        $('#txt_ma_nv').val(row.cells[2].innerHTML);
                        $('#txt_ho').val(row.cells[3].innerHTML);
                        $('#txt_ten').val(row.cells[4].innerHTML);
                        $('#txt_ngay_sinh').val(row.cells[5].innerHTML);
                        $('#txt_dien_thoai').val(row.cells[6].innerHTML);
                        $('#txt_email').val(row.cells[7].innerHTML);
                        $("#cbo_phong_ban").val(row.cells[9].innerHTML);
                        $("#cbo_gioi_tinh").val(row.cells[10].innerHTML);
                        $("#txt_cmnd").val(row.cells[11].innerHTML);
                        $("#txt_ngay_thue").val(getFDate(row.cells[12].innerHTML));
                        $("#txt_dia_chi").val(row.cells[13].innerHTML);
                        $("#txt_ms_thue").val(row.cells[14].innerHTML);
                        $("#txt_ghi_chu").val(row.cells[15].innerHTML);
                        $("#lbl_lan_sua_cuoi").html(row.cells[17].innerHTML);
                       
                        k = i;
                        break;
                    }
                }
                var h = $(window).height() - 239;
                $(".popover-content").css({ 'max-height': h });

            });

            $('#btn_delete').on('shown.bs.popover', function () {
                var tables = document.getElementById("table_nhan_vien");
                var k = 0;
                for (var i = 0; i < tables.rows.length; i++) {
                    var row = tables.rows[i]
                    if (row.className == 'info') {
                        k++;
                    }
                }
                if (k != 0) {
                    $("#msgcontent").html('Bạn có chắc muốn xóa <strong>' + k + '</strong> nhân viên ?');
                }
            });


        });

        function TimPhongBan(ten_phong_ban, tong_so_dong) {

            var DTO = {
                'ten_phong_ban': ten_phong_ban,
                'tong_so_dong': tong_so_dong
            };

            $.ajax({
                type: "POST",
                url: "../BUSINESS/Services.asmx/TimPhongBanTheoTen",
                data: JSON.stringify(DTO),
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    $("#cbo_phong_ban").html('');
                    $.each($.parseJSON(data.d), function (idx, obj) {
                        tong_so_dong += 1;
                        $("#cbo_phong_ban").append(
                            '<option value="' + obj.MA_PHONG_BAN + '">' + obj.TEN_PHONG_BAN + '</option>');
                    });

                },
                error: function (data) {
                    console.log(data.d);
                }

            });
        }


    </script>
</asp:Content>
